﻿﻿<script lang="ts" name="storeProcessFlowStep" setup>
import { ref, reactive, onMounted } from "vue";
import { ElMessage } from "element-plus";
import type { FormRules } from "element-plus";
import { formatDate } from '/@/utils/formatTime';
import { useStoreProcessFlowStepApi } from '/@/api/store/storeProcessFlowStep';

//父级传递来的函数，用于回调
const emit = defineEmits(["reloadTable"]);
const storeProcessFlowStepApi = useStoreProcessFlowStepApi();
const ruleFormRef = ref();

const state = reactive({
	title: '',
	loading: false,
	showDialog: false,
	readonly: false,
	ruleForm: {} as any,
	stores: {},
	dropdownData: {} as any,
});

// 自行添加其他规则
const rules = ref<FormRules>({
  flowType: [{required: true, message: '请选择审批类型！', trigger: 'blur',},],
  requestNo: [{required: true, message: '请选择申请号！', trigger: 'blur',},],
  applicantId: [{required: true, message: '请选择申请人ID！', trigger: 'blur',},],
  statusNewOrChange: [{required: true, message: '请选择新增或更新！', trigger: 'change',},],
  approvalAction: [{required: true, message: '请选择审批状态！', trigger: 'change',},],
});

// 页面加载时
onMounted(async () => {
});

// 打开弹窗
const openDialog = async (row: any, title: string, readonly: boolean = false) => {
	state.title = title;
	state.readonly = readonly;
	row = row ?? {  };
	state.ruleForm = row.id ? await storeProcessFlowStepApi.detail(row.id).then(res => res.data.result) : JSON.parse(JSON.stringify(row));
	state.showDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
	emit("reloadTable");
	state.showDialog = false;
};

// 提交
const submit = async () => {
	ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
		if (isValid) {
			let values = state.ruleForm;
			await storeProcessFlowStepApi[state.ruleForm.id ? 'update' : 'add'](values);
			closeDialog();
		} else {
			ElMessage({
				message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
				type: "error",
			});
		}
	});
};

//将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>
<template>
	<div class="storeProcessFlowStep-container">
		<el-dialog v-model="state.showDialog" :width="800" draggable :close-on-click-modal="false">
			<template #header>
				<div style="color: #fff">
					<span>{{ state.title }}</span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
				<el-row :gutter="35">
					<el-form-item v-show="false">
						<el-input v-model="state.ruleForm.id" />
					</el-form-item>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="审批类型" prop="flowType">
							<el-input v-model="state.ruleForm.flowType" placeholder="请输入审批类型" maxlength="255" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="申请批次" prop="batchNo">
							<el-input v-model="state.ruleForm.batchNo" placeholder="请输入申请批次" maxlength="255" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="申请号" prop="requestNo">
							<el-input v-model="state.ruleForm.requestNo" placeholder="请输入申请号" maxlength="255" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="分类Id" prop="storeTypeId">
							<el-input v-model="state.ruleForm.storeTypeId" placeholder="请输入分类Id" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="分类名称" prop="storeTypeName">
							<el-input v-model="state.ruleForm.storeTypeName" placeholder="请输入分类名称" maxlength="128" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="物资Id" prop="materialId">
							<el-input v-model="state.ruleForm.materialId" placeholder="请输入物资Id" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="物资名称" prop="materialName">
							<el-input v-model="state.ruleForm.materialName" placeholder="请输入物资名称" maxlength="128" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="物资单价" prop="materialPrice">
							<el-input-number v-model="state.ruleForm.materialPrice" placeholder="请输入物资单价" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="申请数量" prop="quantity">
							<el-input-number v-model="state.ruleForm.quantity" placeholder="请输入申请数量" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="单位" prop="unit">
							<el-input v-model="state.ruleForm.unit" placeholder="请输入单位" maxlength="32" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="物资总价" prop="materialPriceTotal">
							<el-input-number v-model="state.ruleForm.materialPriceTotal" placeholder="请输入物资总价" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="申请人ID" prop="applicantId">
							<el-input v-model="state.ruleForm.applicantId" placeholder="请输入申请人ID" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="申请人姓名" prop="applicantName">
							<el-input v-model="state.ruleForm.applicantName" placeholder="请输入申请人姓名" maxlength="255" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="申请人区域" prop="applicantDept">
							<el-input v-model="state.ruleForm.applicantDept" placeholder="请输入申请人区域" maxlength="255" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="接收人Id" prop="receiverId">
							<el-input v-model="state.ruleForm.receiverId" placeholder="请输入接收人Id" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="接收人姓名" prop="receiverName">
							<el-input v-model="state.ruleForm.receiverName" placeholder="请输入接收人姓名" maxlength="255" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="接收人区域" prop="receiverDept">
							<el-input v-model="state.ruleForm.receiverDept" placeholder="请输入接收人区域" maxlength="255" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="申请时间" prop="requestTime">
							<el-date-picker v-model="state.ruleForm.requestTime" type="date" placeholder="申请时间" value-format="YYYY-MM-DD" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="预期时间" prop="expectedDate">
							<el-date-picker v-model="state.ruleForm.expectedDate" type="date" placeholder="预期时间" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="完成时间" prop="completedTime">
							<el-date-picker v-model="state.ruleForm.completedTime" type="date" placeholder="完成时间" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="新增或更新" prop="statusNewOrChange">
							<g-sys-dict v-model="state.ruleForm.statusNewOrChange" code="StatusNewOrChangeEnum" render-as="select" placeholder="请选择新增或更新" clearable filterable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="备注" prop="remark">
							<el-input v-model="state.ruleForm.remark" placeholder="请输入备注" maxlength="128" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="审批状态" prop="approvalAction">
							<g-sys-dict v-model="state.ruleForm.approvalAction" code="StatusApprovalEnum" render-as="select" placeholder="请选择审批状态" clearable filterable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="确认负责人ID" prop="confirmerId">
							<el-input v-model="state.ruleForm.confirmerId" placeholder="请输入确认负责人ID" show-word-limit clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="确认负责人姓名" prop="confirmerName">
							<el-input v-model="state.ruleForm.confirmerName" placeholder="请输入确认负责人姓名" maxlength="64" show-word-limit clearable />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="() => state.showDialog = false">取 消</el-button>
					<el-button @click="submit" type="primary" v-reclick="1000">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>
<style lang="scss" scoped>
:deep(.el-select), :deep(.el-input-number) {
  width: 100%;
}
</style>